<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :duration="1000" :interval="3000">
			<swiper-item v-for="(item, index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, index) in navList" :key="index" @click="navClickHandler(item)">
				<image :src="item.image_src" class="nav-image"></image>
			</view>
		</view>
		<!-- 楼层 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item, index) in floorList" :key="index">
				<!-- 楼层标题 -->
				<image class="floor-title" :src="item.floor_title.image_src"></image>
				<!-- 楼层图片 -->
				<view class="floor-img-box">
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" :style="{width: `${item.product_list[0].image_width}rpx`}" mode="widthFix"></image>
					</navigator>
					<view class="right-img-box">
						<navigator class="right-img-item" v-for="(rightImgItem, rightImgIndex) in item.product_list" :key="rightImgIndex"  :url="rightImgItem.url" v-if="rightImgIndex != 0">
							<image :src="rightImgItem.image_src" :style="{width: `${rightImgItem.image_width}rpx`}" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				navList:[],
				floorList:[],
			};
		},
		onLoad() {
			this.getSwiperList();
			this.getNavList();
			this.getFloorList();
		},
		methods:{
			// 获取轮播图数据
			async getSwiperList() {
				const {data: resData} = await uni.$http.get('/api/public/v1/home/swiperdata');
				if(resData.meta.status == 200) this.swiperList = resData.message;
			},
			// 获取导航数据
			async getNavList() {
				const {data: resData} = await uni.$http.get('/api/public/v1/home/catitems');
				if(resData.meta.status == 200) this.navList = resData.message;
			},
			// 获取楼层数据
			async getFloorList() {
				const {data: resData} = await uni.$http.get('/api/public/v1/home/floordata');
				if(resData.meta.status == 200)  {
					resData.message.forEach(floor => {
						floor.product_list.forEach(prod => {
							prod.url = `/subpkg/goods_list/goods_list?${prod.navigator_url.split('?')[1]}`;
						})
					})
					this.floorList = resData.message;
				}
			},
			navClickHandler(item) {
				if(item.name == '分类') {
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
swiper {
	height: 300rpx;
	.swiper-item,image {
			width: 100%;
			height: 100%;
	}
}
.nav-list {
	display: flex;
	justify-content: space-around;
	margin: 15rpx auto;
	.nav-image {
		width: 128rpx;
		height: 140rpx;
	}
}
.floor-title {
	width: 100%;
	height: 60rpx;
}
.floor-img-box {
	display: flex;
	padding-left: 10rpx;
	.right-img-box {
		display: flex;
		justify-content: space-around;
		flex-wrap: wrap;
	}
}
</style>
